package Server;

import java.util.ArrayList;
import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.codehaus.jettison.json.JSONObject;

import Server.BusinessObjects.Category;
import Server.BusinessObjects.Config;

@Path("/severity")
public class SeverityResource {

	@GET
	@Produces(MediaType.APPLICATION_JSON)
	@Path("/{categoryId}")
	public String getSeveritiesToCategory(@PathParam("categoryId") int categoryId) {

		
		List<JSONObject> objects = new ArrayList<JSONObject>();
		try {
			List <Integer> severities = Category.getSeveritiesToCategory(categoryId);
			List<Integer> alreadyAdded = new ArrayList<Integer>();
			for(Integer s : severities) {
				int count=0;
				for(Integer s1: severities){
					if(s1.equals(s)){
						count++;
					}
				}
				if(count>=Config.minQuestionInSeverity && !alreadyAdded.contains(s)){
					
					JSONObject o = new JSONObject();
					o.put("Severity", s);

					objects.add(o);
					
					alreadyAdded.add(s);
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return objects.toString();
	}
}
